package metrics

import "github.com/prometheus/client_golang/prometheus"

// CreateTotalRequestsMetric 创建新的计数器 CounterVec 多个监控指标集合 数值只增不减
func CreateTotalRequestsMetric(namespace string) *prometheus.CounterVec {
	return prometheus.NewCounterVec(
		prometheus.CounterOpts{
			Namespace: namespace,
			Name:      "Http_request_total",
			Help:      "The total number of handled HTTP Requests.",
		}, []string{"path", "TotalRequest"})

}

// NewTotalRequestCounter 生成新的自定义结构体 RequestCounter
func NewTotalRequestCounter(counter *prometheus.CounterVec, url string, amethod string) *RequestCounter {
	return &RequestCounter{
		counter: counter,
		path:    url,
		cmethod: amethod,
	}
}

// ObserveRequestTotal 链接访问统计，自动递增
func (r *RequestCounter) ObserveRequestTotal() {
	(r.counter).WithLabelValues(r.path, r.cmethod).Inc()
}

type RequestCounter struct {
	counter *prometheus.CounterVec
	path    string
	cmethod string
}
